﻿#pragma once
#include <functional>
#include <stdint.h>
#include <vector>

#include "pthread.h"

#include "HiUnSafeSmartHeapList.h"

class HiPicShare {
  public:
    using SHARE_FUN = std::function<void(const uint8_t *, uint32_t)>;

  public:
    HiPicShare();
    ~HiPicShare();

  public:
    bool Start(uint32_t width, uint32_t shareSize, const SHARE_FUN &share_fun);
    void Stop();

  public:
    void OnPic(const uint8_t *bgr, uint32_t width, uint32_t height);

  private:
    void HandlePic();
    void HandleFrontPic();
    uint8_t *readFrontPic();
    void AbandonFrontPic();

  public:
    void onThread();

  private:
    HiUnSafeSmartHeapList bgrHeap;
    std::vector<uint8_t *> bgrList;
    uint32_t shareSize;
    uint32_t startWidth;
    bool isExit{false};

    SHARE_FUN shareFunction;
    pthread_t shareThread{0};
};
